<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
		<title>物业管理系统</title>
		
		<base href="<%=basePath%>">
		<link rel="stylesheet" href="css/bootstrap.css">
		<link rel="stylesheet" href="css/vivo.css">
		<link rel="stylesheet" href="css/cmxform.css">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<link rel="stylesheet" href="js/zTree_v3/css/metroStyle/metroStyle.css" >
		
		<script src="js/jquery-1.11.1.js"></script>
		<link href="js/select2/select2.min.css" type="text/css" rel="stylesheet" />
		<script src="js/select2/select2.min.js"></script>
		<script src="js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
		<script src="js/jquery.validation/1.14.0/messages_zh.min.js"></script>
		<script type="text/javascript" src="js/sharefunction.js"></script>
		
		<script type="text/javascript" src="js/zTree_v3/js/jquery.ztree.core.min.js" ></script>
		<script type="text/javascript" src="js/zTree_v3/js/jquery.ztree.excheck.min.js" ></script>
		<script type="text/javascript" src="static/dept-select-list.js" ></script>

		<style type="text/css">
			.primary-vdd {
				color: #fff;
				background-color: #5a98de;
				border-color: #5a98de
			}
			
			.primary-vdd:hover {
				color: #fff;
				background-color: #0a6999;
				border-color: #0a6999
			}
		</style>
		<script type="text/javascript">
			
			//绑定字典内容到指定的Select控件
			function BindSelect(ctrlName, url) {
			    var control = $('#' + ctrlName);
			    //设置Select2的处理
			    control.select2({
			        allowClear: true,
			        //formatResult: formatResult,
			        //formatSelection: formatSelection,
			        escapeMarkup: function (m) {
			            return m;
			        }
			    });
			    
			    //绑定Ajax的内容
			    $.getJSON(url,function(data){ 
			    	//control.empty();//清空下拉框
			    	var dataArray = eval('(' + data + ')');
			    	
			    	for(var i=0;i<dataArray.length;i++){
			    		control.append("<option value='" + dataArray[i].id + "'>&nbsp;" + dataArray[i].orgName + "</option>");
			    	}
			    	//绑定默认值
			    	control.val(dataArray[0].id).trigger("change"); 
			    });
			    
			}
		
			$.validator.setDefaults({
				submitHandler : function() {
					saveDocument();
				}
			});
		
			$(document).ready(function() {
				var url = "admin/org/dept/json/root";
				
				$("#lockState").select2({
					minimumResultsForSearch : -1
				});
				
				BindSelect("orgId", url);
				
				$("#commentForm").validate({
					errorPlacement : function(error, element) {
						// Append error within linked label
						$(element).next().append(error);
					},
					errorElement : "span",
					rules : {
						reading : {
							maxlength : 9,
							max : 999999,
							min : 0
						},loginPwd2: {
					        required: true,
					        equalTo: "#loginPwd"
					     }
					},
					messages : {
						typeName : {
							required : " 必需字段!",
							minlength : " (不能少于 3 个字母)"
						},
						unitNumber : {
							required : " 必须字段！ "
						},loginPwd2: {
							equalTo:"两次密码输入不一致！"
						}
					}
		
				});
			});
		
			function saveDocument() {
				var id = $("#id").val();
				var orgId = $("#deptSelectValue").val();
				if(orgId=="root"){
					alert("请选择用户组织哦！");
					return false;
				}
				var userRelationType = "0";
				var userId = $("#userId").val();
				var userName = $("#userName").val();
				var loginPwd = $("#loginPwd").val();
				var mobileNumber = $("#mobileNumber").val();
				var userTitle = $("#userTitle").val();
				var lockState = $("#lockState").val();
				var sortNum = $("#sortNum").val();
				
				var url = "admin/org/user/save";
				
				jQuery.ajax({
					type : "post",
					async : false,
					url : url,
					dataType : "json",
					data : {
						id : id,
						orgId : orgId,
						userRelationType : userRelationType,
						userId : userId,
						userName : userName,
						loginPwd : loginPwd,
						mobileNumber : mobileNumber,
						userTitle:userTitle,
						lockState:lockState,
						sortNum:sortNum
					},
					success : function(data) {
						if (data.success) {
							alert(data.msg);
							location.href="admin/org/user/list";
						} else {
							alert(data.msg);
						}
					}
				});
			}
		</script>
	
	</head>
	<body>
		<form class="cmxform" id="commentForm" method="post">
			<div style="padding: 20px">
				<div class="panel panel-default">
					<div class="panel-heading">
						<h5 class="panel-title">用户信息</h5>
					</div>
					<div class="panel-body">
						<table cellpadding="10" cellspacing="5" class="mytable">
							<tr>
								<td width="90">所属组织</td>
								<td width="300px">
									<!-- <select id="orgId" style="width: 260px;"></select> -->
									<input type="text" id="deptSelectView" name="deptSelectView" style="width: 270px;display: inline-block;cursor:pointer;" placeholder="点击选择..." readonly="readonly" class="form-control" >
									<input type="hidden" id="deptSelectValue" name="deptSelectValue" >
									<ul id="deptTree" class="ztree" style="display: none;" ></ul>
								</td>
								<td></td>
								<td>
								</td>
							</tr>
							<tr>
								<td width="90">登录名称</td>
								<td>
									<input type="text" name="userId" id="userId" required />
									<font color="red"> *</font>
									<span style="color: red"></span>
								</td>
								<td>中文名称</td>
								<td>
									<input type="text" name="userName" id="userName" required />
									<font color="red"> *</font>
									<span style="color: red"></span>
								</td>
							</tr>
							<tr>
								<td width="90">登录密码</td>
								<td>
									<input type="password" name="loginPwd" id="loginPwd" required />
									<font color="red"> *</font>
									<span style="color: red"></span>
								</td>
								<td>密码确认</td>
								<td>
									<input type="password" name="loginPwd2" id="loginPwd2" required />
									<font color="red"> *</font>
									<span style="color: red"></span>
								</td>
							</tr>
							<tr>
								<td>手机号码</td>
								<td>
									<input type="text" name="mobileNumber" id="mobileNumber" />
									<span style="color: red"></span>
								</td>
								<td>职称</td>
								<td>
									<input type="text" name="userTitle" id="userTitle" >
								</td>
							</tr>
							<tr>
								<td width="90">状态</td>
								<td>
									<select id="lockState" name="lockState" style="width: 90px;">
										<option value="0">正常</option>
										<option value="1">锁定</option>
									</select>
								</td>
								<td>用户排序</td>
								<td>
									<input type="text" name="sortNum" id="sortNum" >
								</td>
							</tr>
						</table>
					</div>
				</div>
				<div style="width: 100%; text-align: center; padding-top: 20px">
					<button class="btn btn-primary radius primary-vdd" type="submit">保 存</button>
					<a class="btn btn-default radius" onClick="history.back();"> 取 消 </a>
					<br />
					<br />
				</div>
			</div>
	
			<div style="display:none">
				<input id="id" name="id" type="hidden" value="${id}" />
			</div>
		</form>
	</body>
</html>

